/**
 *
 * Created by Song, YeWen, 10/10/2011 6:20:17 PM
 *
 */

function  validateVideoUrl(ori_url) 
{
    //We use a fake constant duration for mtime.com, because it is Movie trailer, not long duration video
    //TODO: FIXME
    var fcduration = '100';  
	var html = download_page(ori_url);
	var matches = html.match(/vid="(\d+)"/);
	if (!matches) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	var dst_url = 'http://api.mtime.com/trailer/getvideo.aspx?vid=' + matches[1];
	var json_str = download_page(dst_url);
	var json = eval('(' + json_str + ')');
	var sb = [];

	if (json && json.flv) {
		var files = json.flv;
		sb.push(files);
	}
	if(sb.length>0){
		//matches = html.match(/<title>(.*?)<\/title>/);
		matches = html.match(/<title>([\s\S]*?)<\/title>/);
	    if(matches){
	 	   return 'success_title:' + encodeURIComponent(matches[1])
	 	          + '\n video_urls:' + encodeURIComponent(sb)
	 	          + '\n seconds:' + Math.round(parseInt(fcduration));
	    }
	}
    return 'error:empty_path';
}

/* http://api.mtime.com/trailer/getvideo.aspx?vid=34833 */
/* http://movie.mtime.com/150164/trailer/34833.html */
function js_get_media_url(ori_url)
{
	var html = download_page(ori_url);
	var matches = html.match(/vid="(\d+)"/);
	if (!matches) {
		// Not Found
		return '';
	}

	var dst_url = 'http://api.mtime.com/trailer/getvideo.aspx?vid=' + matches[1];
	var json_str = download_page(dst_url);
	var json = eval('(' + json_str + ')');
	var sb = [];

	if (json && json.flv) {
		var files = json.flv;
		sb.push(files);
	}
	return sb;
}
